<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<script>
var pbSet = new Set();
function searchpbs(){	
		var productCode = $("#brandInfo").val();

        $('#dataGridBrand').datagrid({
    		url : 'productJSONAction!listProductsDataByPage',    		
    	    queryParams: {
    	    	'formBean.productBarcode.product.productCode':productCode,    	    	
    	    },
    		fit : true,
    		fitColumns : true,
    		pagination : true,
    		pageSize : 10,
    		pageList : [ 10, 20],
    		border : false,
    		checkOnSelect : true,
    		selectOnCheck : true,
    		singleSelect: false,
    		showFooter:true,
    		rownumbers:true,
    		nowrap : false,
    		columns : [[
    					{field:'id', width:40,title:'选择',checkbox: true},	
    				
    					{field:'productCode', width:90,title:'货号',fixed:true},	
    					{field:'color', width:70,title:'颜色',fixed:true},
						{field:'categoryLevel', width:70,title:'产品线',fixed:true},
						{field:'category', width:150,title:'货品种类',fixed:true},						
						{field:'brand', width:140,title:'品牌',fixed:true},	
						{field:'supplier', width:150,title:'厂家',fixed:true},	
						{field:'year', width:70,title:'年',fixed:true},	
						{field:'quarter', width:70,title:'季度',fixed:true},	
						{field:'unit', width:70,title:'单位',fixed:true},	
						{field:'wholePrice1', width:70,title:'预设价1',fixed:true},	
						{field:'wholePrice2', width:70,title:'预设价2',fixed:true},	
						 {				
							field : 'action',
							title : '选择',
							width : 60,
						formatter : function(value, row, index) {							
							var str = '';
							str += $.formatString('<a href="#" onclick="selectBrand(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="货品"/></a>', row.id,row.productCode,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/select.png');
							return str;
						}},
    			     ]],	    
    	});
        
        $("#brandDiv").dialog("open");
}
//选中货品
function selectBrand(pbId,productCode){

	var pbs = $("#pbs").val();
	if(pbs != null && pbs != ""){
		pbs += ","+pbId;
		$("#pbs").val(pbs);
	}else{
		$("#pbs").val(pbId);
	}
	pbSet.add(pbId);
	//已选货品数量信息
	let brandNums = pbSet.size;	
	$("#brandNums").val(brandNums);
	 $.messager.show({
         title:'选择货品提示',
         msg:productCode +'货号加入已选货品',
         showType:'slide',
         timeout:100,
         style:{
        	 left:'',
             right:0,
             top:document.body.scrollTop+document.documentElement.scrollTop,
             bottom:''
         }
     });
	$("#brandDiv").dialog("close");
	
}
//查看已选货品
function searchFilterpbs(){
	
	var pbs = $("#pbs").val();
    $('#brandGrid').datagrid({
		url : 'productJSONAction!listpbsData',    		
	    queryParams: {
	    	'formBean.pbIds':pbs,    	    	
	    },
		fit : true,
		fitColumns : true,
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		rownumbers:true,
		nowrap : false,
		columns : [[
			{field:'id', width:40,title:'选择',checkbox: true},	
			
			{field:'productCode', width:120,title:'货号',fixed:true},	
			{field:'color', width:70,title:'颜色',fixed:true},
			{field:'categoryLevel', width:70,title:'产品线',fixed:true},
			{field:'category', width:150,title:'货品种类',fixed:true},			
			{field:'brand', width:140,title:'品牌',fixed:true},	
			{field:'supplier', width:150,title:'厂家',fixed:true},	
			{field:'year', width:70,title:'年',fixed:true},	
			{field:'quarter', width:70,title:'季度',fixed:true},	
			{field:'unit', width:70,title:'单位',fixed:true},	
			{field:'wholePrice1', width:70,title:'预设价1',fixed:true},	
			{field:'wholePrice2', width:70,title:'预设价2',fixed:true},					
					 {				
						field : 'action',
						title : '删除',
						width : 60,
					formatter : function(value, row, index) {							
						var str = '';
						str += $.formatString('<a href="#" onclick="deleteBrand(\'{0}\');"><img border="0" src="{1}" title="货品"/></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/delete2.png');
						return str;
					}},
			     ]],

	});
	$('#selectBrandDiv').dialog('open')
}
//根据货品ID删除已选货品
function deleteBrand(pbId){
	pbSet.delete(pbId);
	var pbIds = "";
	pbSet.values().forEach(item => {
		pbIds += item + ","
	    });
	if(pbIds.length>1){
		pbIds = pbIds.substr(0,pbIds.length-1);
	}
	$("#pbs").val(pbIds);
	let brandNums = pbSet.size;	
	$("#brandNums").val(brandNums);
	searchFilterpbs();	
}
//清空已选货品
function deletepbs(){
	$("#pbs").val('');
	pbSet.clear();
	$("#brandNums").val(0);
	searchFilterpbs();
	$('#selectBrandDiv').dialog('close')
}

//所有checkbox 选中的货品
function selectpbs(){
	
	var rows = $('#dataGridBrand').datagrid('getChecked');
	
	if(rows.length != 0){
		for(let i = 0;i<rows.length;i++){
			var pbs = $("#pbs").val();
			let pbId = String(rows[i].id);
			if(pbs != null && pbs != ""){
				pbs += ","+pbId;				
			}else{
				pbs += pbId;	
			}
			$("#pbs").val(pbs);			

			pbSet.add(pbId);
			//已选货品数量信息
			let brandNums = pbSet.size;				
			$("#brandNums").val(brandNums);
		}
	}
	$("#brandDiv").dialog("close");
}

</script>

<s:form id="brandForm" name="brandForm" action="" theme="simple" method="POST">

	<table  border="0"  class="InnerTableContent">
		<tr>
			<td width="200"><s:textfield cssClass="easyui-searchbox" id="brandInfo" data-options="prompt:'请输入货号/条码',searcher:searchpbs"  size="20" /></td>							
			<td width="120" >
				<a onclick="searchFilterpbs();" href="javascript:void(0);" class="easyui-linkbutton c6" style="height:25px;" data-options="iconCls:'icon-filter'">已选货品</a>
			</td>
			<td width="20" >	<input type="button" id="brandNums" style="height:25px;width:28px;color:red;text-align:center;border-radius:30%"  disabled="disabled">
			</td>
		</tr>
		</table>

</s:form>
<input type="hidden" id="pbs" name="formBean.pbIds"/>
<!-- 查找货品 -->
<div id="brandDiv" class="easyui-dialog" style="width: 1200px; height: 410px" data-options="title:'查找货品',modal:false,closed:true,resizable:true">	
			<a onclick="selectpbs();" href="javascript:void(0);" class="easyui-linkbutton c5" style="height:25px;" data-options="">确认选择</a>
		    <div id="cc" class="easyui-layout" style="width:1180px;height:330px; position: relative; top:5px;">
		    
		    	<table id="dataGridBrand" border="0" >
				</table>
		    </div>
</div>

<!-- 已选货品 -->
<div id="selectBrandDiv" class="easyui-dialog" style="width: 1200px; height: 410px" data-options="title:'已选货品',modal:false,closed:true,resizable:true">

<a onclick="deletepbs();" href="javascript:void(0);" class="easyui-linkbutton c5" style="height:25px;" data-options="">一键清空</a>
	<table id="brandGrid"  border="0">
	</table>
</div>